import java.util.HashSet;
import java.util.Set;

class Solution {
    public int lengthOfLongestSubstring(String s) {
        if (s.length() <= 1) {
            return s.length();
        }
        int maxCount = 1;
        for (int i = 0; i <= s.length(); i++) {
            for (int j = i+1; j <= s.length(); j++) {
                int count = getMaxCount(s.substring(i, j));
                if (count > maxCount) {
                    maxCount = count;
                }
            }
        }
        return maxCount;
    }

    private int getMaxCount(String substring) {
        Set<Character> occ = new HashSet<Character>();

        if (substring.length() <= 1) {
            return substring.length();
        }
        int count = 1;
        for (int m = 1; m < substring.length(); m++) {
            for (int k = m - 1; k >= 0; k--) {
                if (substring.charAt(k) == substring.charAt(m)) {
                    return count;
                }
            }
            count++;
        }

        return count;
    }
}